home *** CD-ROM | disk | FTP | other *** search
/ Micromanía: 150 Juegos 2010 / 150Juegos_16.iso / Shareware / Shape Smash / shape-smash.swf / scripts / mx / controls / ToolTip.as < prev    next >
Encoding:
Text File  |  2010-05-14  |  5.2 KB  |  167 lines

  1. package mx.controls
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.text.TextFieldAutoSize;
  5.    import flash.text.TextFormat;
  6.    import mx.core.EdgeMetrics;
  7.    import mx.core.IFlexDisplayObject;
  8.    import mx.core.IToolTip;
  9.    import mx.core.UIComponent;
  10.    import mx.core.UITextField;
  11.    import mx.core.mx_internal;
  12.    import mx.skins.RectangularBorder;
  13.    import mx.styles.ISimpleStyleClient;
  14.    
  15.    use namespace mx_internal;
  16.    
  17.    public class ToolTip extends UIComponent implements IToolTip
  18.    {
  19.       mx_internal static const VERSION:String = "2.0.1.0";
  20.       
  21.       public static var maxWidth:Number = 300;
  22.       
  23.       mx_internal var border:IFlexDisplayObject;
  24.       
  25.       private var textChanged:Boolean;
  26.       
  27.       private var _text:String;
  28.       
  29.       protected var textField:UITextField;
  30.       
  31.       public function ToolTip()
  32.       {
  33.          super();
  34.          mouseEnabled = false;
  35.       }
  36.       
  37.       mx_internal function getTextField() : UITextField
  38.       {
  39.          return textField;
  40.       }
  41.       
  42.       public function get text() : String
  43.       {
  44.          return _text;
  45.       }
  46.       
  47.       override protected function measure() : void
  48.       {
  49.          var _loc1_:EdgeMetrics = null;
  50.          var _loc2_:Number = NaN;
  51.          var _loc3_:Number = NaN;
  52.          var _loc4_:Number = NaN;
  53.          var _loc5_:Number = NaN;
  54.          var _loc6_:Number = NaN;
  55.          var _loc7_:Number = NaN;
  56.          super.measure();
  57.          _loc1_ = borderMetrics;
  58.          _loc2_ = _loc1_.left + getStyle("paddingLeft");
  59.          _loc3_ = _loc1_.top + getStyle("paddingTop");
  60.          _loc4_ = _loc1_.right + getStyle("paddingRight");
  61.          _loc5_ = _loc1_.bottom + getStyle("paddingBottom");
  62.          _loc6_ = _loc2_ + _loc4_;
  63.          _loc7_ = _loc3_ + _loc5_;
  64.          textField.wordWrap = false;
  65.          if(textField.textWidth + _loc6_ > ToolTip.maxWidth)
  66.          {
  67.             textField.width = ToolTip.maxWidth - _loc6_;
  68.             textField.wordWrap = true;
  69.          }
  70.          measuredWidth = textField.width + _loc6_;
  71.          measuredHeight = textField.height + _loc7_;
  72.       }
  73.       
  74.       override protected function commitProperties() : void
  75.       {
  76.          var _loc1_:TextFormat = null;
  77.          super.commitProperties();
  78.          if(textChanged)
  79.          {
  80.             _loc1_ = textField.getTextFormat();
  81.             _loc1_.leftMargin = 0;
  82.             _loc1_.rightMargin = 0;
  83.             textField.defaultTextFormat = _loc1_;
  84.             textField.text = _text;
  85.             textChanged = false;
  86.          }
  87.       }
  88.       
  89.       public function set text(param1:String) : void
  90.       {
  91.          _text = param1;
  92.          textChanged = true;
  93.          invalidateProperties();
  94.          invalidateSize();
  95.          invalidateDisplayList();
  96.       }
  97.       
  98.       override protected function createChildren() : void
  99.       {
  100.          var _loc1_:Class = null;
  101.          super.createChildren();
  102.          if(!mx_internal::border)
  103.          {
  104.             _loc1_ = getStyle("borderSkin");
  105.             mx_internal::border = new _loc1_();
  106.             if(mx_internal::border is ISimpleStyleClient)
  107.             {
  108.                ISimpleStyleClient(mx_internal::border).styleName = this;
  109.             }
  110.             addChild(DisplayObject(mx_internal::border));
  111.          }
  112.          if(!textField)
  113.          {
  114.             textField = new UITextField();
  115.             textField.autoSize = TextFieldAutoSize.LEFT;
  116.             textField.mouseEnabled = false;
  117.             textField.multiline = true;
  118.             textField.selectable = false;
  119.             textField.wordWrap = false;
  120.             textField.styleName = this;
  121.             addChild(textField);
  122.          }
  123.       }
  124.       
  125.       private function get borderMetrics() : EdgeMetrics
  126.       {
  127.          if(mx_internal::border is RectangularBorder)
  128.          {
  129.             return RectangularBorder(mx_internal::border).borderMetrics;
  130.          }
  131.          return EdgeMetrics.EMPTY;
  132.       }
  133.       
  134.       override public function styleChanged(param1:String) : void
  135.       {
  136.          super.styleChanged(param1);
  137.          if(param1 == "borderStyle" || param1 == "styleName" || param1 == null)
  138.          {
  139.             invalidateDisplayList();
  140.          }
  141.       }
  142.       
  143.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  144.       {
  145.          var _loc3_:EdgeMetrics = null;
  146.          var _loc4_:Number = NaN;
  147.          var _loc5_:Number = NaN;
  148.          var _loc6_:Number = NaN;
  149.          var _loc7_:Number = NaN;
  150.          var _loc8_:Number = NaN;
  151.          var _loc9_:Number = NaN;
  152.          super.updateDisplayList(param1,param2);
  153.          _loc3_ = borderMetrics;
  154.          _loc4_ = _loc3_.left + getStyle("paddingLeft");
  155.          _loc5_ = _loc3_.top + getStyle("paddingTop");
  156.          _loc6_ = _loc3_.right + getStyle("paddingRight");
  157.          _loc7_ = _loc3_.bottom + getStyle("paddingBottom");
  158.          _loc8_ = _loc4_ + _loc6_;
  159.          _loc9_ = _loc5_ + _loc7_;
  160.          mx_internal::border.setActualSize(param1,param2);
  161.          textField.move(_loc4_,_loc5_);
  162.          textField.setActualSize(param1 - _loc8_,param2 - _loc9_);
  163.       }
  164.    }
  165. }
  166.  
  167.